import {
  AddMobileContactData
} from '@/utils/common-api.js'
export default {
  data() {
    return {
      isPay: false, //是否支付保证金
      storeId: '', //店铺id
      payType: null, //支付方式
      identity: '', //用户角色
      // CarStore 第一大类（4s店、汽贸店、自营卖车）：4s店、汽贸店、7迈直营车 10000 卖车 买车
      // Factory 第二大类（主机+车源商）：车源商、主机厂 5000 卖车
      // BeautyStore 第三大类（养护自营+加盟门店）：美保护精品供应商、7迈直营美护保 无
      // RepairStore 第四大类（维保货源品牌+经销商）：养护门店、7迈直营养护 无
      identityList: [{
        name: 'CarStore',
        money: '10000.00',
        label: '4s店服务'
      },
      {
        name: 'Factory',
        money: '5000.00',
        label: '车源商'
      },
      {
        name: 'BeautyStore',
        money: '5000.00',
        label: '美护保自营'
      },
      {
        name: 'RepairStore',
        money: '5000.00',
        label: '经销商'
      }
      ],
      mShow6: false,
      list: [{
        name: '同时开通'
      },
      {
        name: '商家端'
      },
      {
        name: '消费端'
      }
      ],
      current: 0,
      money: '',
      agree: false
    }
  },
  onLoad(option) {
    this.storeId = this.$store.state.userInfoDetail.store.storeId
    this.identity = this.$store.state.user.userInfo.permious
    this.isPay = this.$store.state.userInfoDetail.store.isPay
    console.log(this.storeId, this.identity, this.isPay)
    if (this.identity === 'CarStore') {
      this.money = '10000.00'
    } else {
      this.money = '5000.00'
    }
  },
  methods: {
    returnIder() {
      let it = {}
      this.identityList.forEach(item => {
        if (item.name === this.identity) {
          it = item
        }
      })
      return it
    },
    async goPay() {
      let data = {
        'orderId': this.storeId,
        'payModule': 6, //商户端保证金
        'payPlatform': {
          'payPlatformType': Number(this.payType),
          'payPlatformDetailType': 3
        },
        // 'returnUrl': 'string'
      }
      if (this.agree) {
        // setTimeout(function() {
        if (this.payType == 1) {
          setTimeout(function() {
            this.mShow6 = true
          }, 2000)
        } else {
          this.mShow6 = false
        }

        // }, 2000)
        console.log(data)
        if (this.payType !== null) {
          let res = await this.$api.pay.PayStoreDepositBalance(data)
          try {
            console.log('支付结果', res.data.data, typeof this.payType)
            // if (res.code === 200) {
            // JSON.parse()
            // this.url = res.data.data
            let payway = ''
            if (this.payType === '0') {
              this.url = res.data.data
              payway = 'alipay'
            } else {
              let data = JSON.parse(res.data.data.parameter)
              this.url = {
                appid: data.appid,
                noncestr: data.noncestr,
                package: data.package,
                partnerid: data.partnerid,
                prepayid: data.prepayid,
                sign: data.sign,
                timestamp: data.timestamp,
              }
              payway = 'wxpay'
            }
            console.log(111, this.url)

            uni.requestPayment({
              provider: payway,
              orderInfo: this.url,
              success: function(res) {
                console.log('success:', res)
                // this.mShow6 = true
                //         uni.redirectTo({

              },
              fail: function(err) {
                console.log('err:', err)
              },
              complete: () => {
                console.log('执行了:')
                uni.redirectTo({
                  url: '/pages_common/pages_me/paySuccess/paySuccess?paytype=2&id=' +
										this.storeId + '&type=' + this.payType
                })
								 // // type 支付方式 0支付宝 1微信  paytype支付类型 0订单 1保证金
                // this.mShow6 = true
              }
            })
            // if (this.payType === '0') {
            // let id = this.url.split('prepay_id=')[1].split('&package=')[0]
            // let pack = this.url.split('&package=')[1]
            // uni.navigateTo({
            //   url: '/pages_order/payLoading/payLoading?paytype=2&id=' + id + '&pack=' + pack+'&dealId='+this.storeId
            // })

            // } else if (this.payType === '1') {
            //   // this.mShow6 = true

            // }
            // }
          } catch (err) {
            console.log(err)
          }
        } else {
          uni.showToast({
            title: '请先选择支付方式',
            icon: 'none',
          })
        }
      } else {
        uni.showToast({
          title: '请先阅读并同意7迈车保证金协议',
          icon: 'none',
        })
      }
    },
    call() {
      AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
      uni.makePhoneCall({
        phoneNumber: '4000909987' //仅为示例
      })
    },

    radioChange(val) {
      this.payType = val.detail.value
    },
    confirmHE() {

      uni.redirectTo({
        url: '/pages_common/pages_me/paySuccess/paySuccess?paytype=2&id=' + this.storeId + '&type=' +
					this.payType
      })
    }
  }
}
